package com.example.demo111111.service.impl;

import com.example.demo111111.Result.PageResult;
import com.example.demo111111.dao.AuditProductDao;
import com.example.demo111111.dao.ProductDao;
import com.example.demo111111.entity.AuditProduct;
import com.example.demo111111.entity.Product;
import com.example.demo111111.service.AuditProductService;
import com.example.demo111111.service.ProductService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class AuditProductServiceImpl implements AuditProductService {
    @Resource
    private AuditProductDao auditProductDao;

    @Override
    public Boolean save(AuditProduct product) {
        if (product.getStatus()==null){
            product.setStatus(1);
        }
        product.setCreate_time(LocalDateTime.now());
        product.setUpdate_time(LocalDateTime.now());
        Boolean result=auditProductDao.save(product);
        return result;
    }

    @Override
    public Boolean update(AuditProduct product) {

        product.setUpdate_time(LocalDateTime.now());
        Boolean result=auditProductDao.update(product);
        return result;
    }


    public PageResult pageQuery(AuditProduct product) {
        PageHelper.startPage(product.getPage(),product.getPageSize());
        Page<AuditProduct> page=auditProductDao.pageQuery(product);
        long total=page.getTotal();
        List<AuditProduct> records=page.getResult();
        return new PageResult(total,records);
    }

    @Override
    public Boolean deltete(List<Long> ids) {

        Boolean result = null;
        for (Long id : ids) {
            result = auditProductDao.deleteById(id);
        }
        return result;
    }
}
